home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / share / examples / dtwsm / wsinfo.c.z / wsinfo.c
Encoding:
C/C++ Source or Header  |  2003-11-18  |  17.5 KB  |  643 lines

  1. /*
  2.  * wsinfo.c
  3.  *
  4.  * Copyright 2000, Silicon Graphics, Inc.
  5.  * ALL RIGHTS RESERVED
  6.  * 
  7.  * UNPUBLISHED -- Rights reserved under the copyright laws of the United
  8.  * States.   Use of a copyright notice is precautionary only and does not
  9.  * imply publication or disclosure.
  10.  *
  11.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  12.  * Use, duplication or disclosure by the Government is subject to restrictions
  13.  * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  14.  * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  15.  * in similar or successor clauses in the FAR, or the DOD or NASA FAR
  16.  * Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  17.  * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  18.  *
  19.  * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  20.  * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  21.  * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  22.  * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  23.  * GRAPHICS, INC.
  24.  */
  25. /* $XConsortium: wsinfo.c /main/cde1_maint/1 1995/07/17 16:46:46 drk $ */
  26. /*
  27.  *  (c) Copyright 1993, 1994 Hewlett-Packard Company    
  28.  *  (c) Copyright 1993, 1994 International Business Machines Corp.
  29.  *  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  30.  *  (c) Copyright 1993, 1994 Novell, Inc.
  31.  */
  32.  
  33. /* Demonstrate the CDE Workspace API. */
  34.  
  35. /*  
  36.  * include files  
  37.  */
  38.  
  39. #include <stdio.h>
  40. #include <Xm/XmAll.h>
  41. #include <Dt/Wsm.h>
  42.  
  43. /*  
  44.  * functions
  45.  */
  46. void main();
  47. static void quitCB(); 
  48. static void updateCB(); 
  49. static void ShowCurrentWorkspaceInfo();
  50. static DtWsmWsChangeProc wschangecb();
  51. static void InstallXErrorHandler();
  52.  
  53. /*  
  54.  * global variables  
  55.  */
  56. static Widget toplevel;
  57. static Widget wChildren[20];
  58.  
  59. /* 
  60.  * button assignments 
  61.  */
  62. #define QUIT_BUTTON    (wChildren[0])
  63. #define UPDATE_BUTTON    (wChildren[1])
  64. #define SEPARATOR    (wChildren[2])
  65. #define WS_LABEL    (wChildren[3])
  66. #define WS_VALUE    (wChildren[4])
  67. #define TITLE_LABEL    (wChildren[5])
  68. #define TITLE_VALUE    (wChildren[6])
  69. #define BACKDROP_LABEL    (wChildren[7])
  70. #define BACKDROP_VALUE    (wChildren[8])
  71. #define COLORSET_LABEL    (wChildren[9])
  72. #define COLORSET_VALUE    (wChildren[10])
  73. #define SEPARATOR2    (wChildren[11])
  74. #define NUM_CHILDREN    12
  75.  
  76. /*
  77.  * main - main logic for program
  78.  */
  79. void main (argc,argv)
  80.     int argc;
  81.     char **argv;
  82. {
  83.     Widget frame;
  84.     Widget form;
  85.     Widget  top;
  86.     XtAppContext app_context;
  87.     Arg    args[10];
  88.     register int n;
  89.     register int i;
  90.     XmString xms, xmsBlank;
  91.  
  92.     /*  
  93.      * initialize toolkit  
  94.      */
  95.     n = 0;
  96.     XtSetArg (args[n], XmNallowShellResize, True);  n++;
  97.     toplevel = XtAppInitialize (&app_context, "Dtwsinfo", NULL, 0, &argc, argv,
  98.                                 NULL, args, n);
  99.  
  100.     /* 
  101.      * Set up X error handling
  102.      */
  103.     InstallXErrorHandler ();
  104.  
  105.     n = 0;
  106.     XtSetArg (args[n], XmNmarginWidth, 10);  n++;
  107.     XtSetArg (args[n], XmNmarginHeight, 10);  n++;
  108.     frame = XmCreateFrame (toplevel, "frame", args, n);
  109.     XtManageChild (frame);
  110.  
  111.     /*  
  112.      * manager widget 
  113.      */
  114.     n = 0;
  115.     form = XmCreateForm (frame, "form", args, n);
  116.     XtManageChild (form);
  117.  
  118.     /*  
  119.      * create compound string for blank labels
  120.      */
  121.     xmsBlank = XmStringCreateLocalized("   ");
  122.  
  123.     /*******************************************
  124.      * QUIT BUTTON
  125.      ******************************************/
  126.  
  127.     /*  
  128.      * create compound string for the button text  
  129.      */
  130.     xms = XmStringCreateLocalized("Quit");
  131.  
  132.     /*  
  133.      * set up arglist  
  134.      */
  135.     n = 0;
  136.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  137.     XtSetArg (args[n], XmNlabelString, xms);  n++;
  138.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  139.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  140.     /*  
  141.      * create button  
  142.      */
  143.     top = QUIT_BUTTON = XtCreateWidget ("button", xmPushButtonWidgetClass,
  144.       form, args, n);
  145.     XmStringFree(xms);
  146.  
  147.     /*  
  148.      * add callback  
  149.      */
  150.     XtAddCallback (QUIT_BUTTON, XmNactivateCallback, quitCB, NULL);
  151.  
  152.     /*******************************************
  153.      * UPDATE WORKSPACE INFO BUTTON
  154.      ******************************************/
  155.  
  156.     /*  
  157.      * create compound string for the button text  
  158.      */
  159.     xms = XmStringCreateLocalized("Get workspace info");
  160.  
  161.     /*  
  162.      * set up arglist  
  163.      */
  164.     n = 0;
  165.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  166.     XtSetArg (args[n], XmNlabelString, xms);  n++;
  167.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  168.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  169.     XtSetArg (args[n], XmNtopWidget, top); n++;
  170.     /*  
  171.      * create button  
  172.      */
  173.     top = UPDATE_BUTTON = XtCreateWidget ("button", xmPushButtonWidgetClass,
  174.       form, args, n);
  175.     XmStringFree(xms);
  176.  
  177.     /*  
  178.      * add callback  
  179.      */
  180.     XtAddCallback (UPDATE_BUTTON, XmNactivateCallback, updateCB, NULL);
  181.  
  182.     /*******************************************
  183.      * SEPARATOR
  184.      ******************************************/
  185.  
  186.     /*  
  187.      * set up arglist  
  188.      */
  189.     n = 0;
  190.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  191.     XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  192.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  193.     XtSetArg (args[n], XmNtopWidget, top); n++;
  194.     /*  
  195.      * create separator  
  196.      */
  197.     top = SEPARATOR = (Widget) 
  198.         XmCreateSeparatorGadget (form, "separator", args, n);
  199.  
  200.     /*******************************************
  201.      * LABEL FOR CURRENT WORKSPACE
  202.      ******************************************/
  203.  
  204.     /*
  205.      * NOTE: We assume this is the longest label and lay out the
  206.      *       other fields based on this assumption.
  207.      */
  208.  
  209.     /*  
  210.      * create compound string for the label text  
  211.      */
  212.     xms = XmStringCreateLocalized("Current workspace: ");
  213.  
  214.     /*  
  215.      * set up arglist  
  216.      */
  217.     n = 0;
  218.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  219.     XtSetArg (args[n], XmNlabelString, xms);  n++;
  220.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  221.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  222.     XtSetArg (args[n], XmNtopWidget, top); n++;
  223.     /*  
  224.      * create label  
  225.      */
  226.     WS_LABEL = XtCreateWidget ("label", xmLabelWidgetClass,
  227.       form, args, n);
  228.     XmStringFree (xms);
  229.  
  230.     /*******************************************
  231.      * VALUE FOR CURRENT WORKSPACE
  232.      ******************************************/
  233.  
  234.     /*  
  235.      * set up arglist  
  236.      */
  237.     n = 0;
  238.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  239.     XtSetArg (args[n], XmNlabelString, xmsBlank);  n++;
  240.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  241.     XtSetArg (args[n], XmNleftWidget, WS_LABEL); n++;
  242.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  243.     XtSetArg (args[n], XmNtopWidget, top); n++;
  244.     /*  
  245.      * create value
  246.      */
  247.     top = WS_VALUE = XtCreateWidget ("label", xmLabelWidgetClass,
  248.       form, args, n);
  249.  
  250.     /*******************************************
  251.      * LABEL FOR WORKSPACE TITLE
  252.      ******************************************/
  253.  
  254.     /*  
  255.      * create compound string for the label text  
  256.      */
  257.     xms = XmStringCreateLocalized("    title: ");
  258.  
  259.     /*  
  260.      * set up arglist  
  261.      */
  262.     n = 0;
  263.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  264.     XtSetArg (args[n], XmNlabelString, xms);  n++;
  265.     XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  266.     XtSetArg (args[n], XmNrightWidget, WS_LABEL); n++;
  267.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  268.     XtSetArg (args[n], XmNtopWidget, top); n++;
  269.     /*  
  270.      * create label  
  271.      */
  272.     TITLE_LABEL = XtCreateWidget ("label", xmLabelWidgetClass,
  273.       form, args, n);
  274.     XmStringFree(xms);
  275.  
  276.     /*******************************************
  277.      * VALUE FOR WORKSPACE TITLE
  278.      ******************************************/
  279.  
  280.     /*  
  281.      * set up arglist  
  282.      */
  283.     n = 0;
  284.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  285.     XtSetArg (args[n], XmNlabelString, xmsBlank);  n++;
  286.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  287.     XtSetArg (args[n], XmNleftWidget, TITLE_LABEL); n++;
  288.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  289.     XtSetArg (args[n], XmNtopWidget, top); n++;
  290.     /*  
  291.      * create value
  292.      */
  293.     top = TITLE_VALUE = XtCreateWidget ("label", xmLabelWidgetClass,
  294.       form, args, n);
  295.  
  296.     /*******************************************
  297.      * LABEL FOR WORKSPACE BACKDROP
  298.      ******************************************/
  299.  
  300.     /*  
  301.      * create compound string for the label text  
  302.      */
  303.     xms = XmStringCreateLocalized("    backdrop: ");
  304.  
  305.     /*  
  306.      * set up arglist  
  307.      */
  308.     n = 0;
  309.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  310.     XtSetArg (args[n], XmNlabelString, xms);  n++;
  311.     XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  312.     XtSetArg (args[n], XmNrightWidget, WS_LABEL); n++;
  313.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  314.     XtSetArg (args[n], XmNtopWidget, top); n++;
  315.     /*  
  316.      * create label  
  317.      */
  318.     BACKDROP_LABEL = XtCreateWidget ("label", xmLabelWidgetClass,
  319.       form, args, n);
  320.     XmStringFree (xms);
  321.  
  322.     /*******************************************
  323.      * VALUE FOR WORKSPACE BACKDROP
  324.      ******************************************/
  325.  
  326.     /*  
  327.      * set up arglist  
  328.      */
  329.     n = 0;
  330.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  331.     XtSetArg (args[n], XmNlabelString, xmsBlank);  n++;
  332.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  333.     XtSetArg (args[n], XmNleftWidget, BACKDROP_LABEL); n++;
  334.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  335.     XtSetArg (args[n], XmNtopWidget, top); n++;
  336.     /*  
  337.      * create value
  338.      */
  339.     top = BACKDROP_VALUE = XtCreateWidget ("label", xmLabelWidgetClass,
  340.       form, args, n);
  341.  
  342.     /*******************************************
  343.      * LABEL FOR WORKSPACE COLORSET ID
  344.      ******************************************/
  345.  
  346.     /*  
  347.      * create compound string for the label text  
  348.      */
  349.     xms = XmStringCreateLocalized("    color set id: ");
  350.  
  351.     /*  
  352.      * set up arglist  
  353.      */
  354.     n = 0;
  355.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  356.     XtSetArg (args[n], XmNlabelString, xms);  n++;
  357.     XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  358.     XtSetArg (args[n], XmNrightWidget, WS_LABEL); n++;
  359.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  360.     XtSetArg (args[n], XmNtopWidget, top); n++;
  361.     /*  
  362.      * create label  
  363.      */
  364.     COLORSET_LABEL = XtCreateWidget ("label", xmLabelWidgetClass,
  365.       form, args, n);
  366.     XmStringFree (xms);
  367.  
  368.     /*******************************************
  369.      * VALUE FOR WORKSPACE COLORSET ID
  370.      ******************************************/
  371.  
  372.     /*  
  373.      * set up arglist  
  374.      */
  375.     n = 0;
  376.     XtSetArg (args[n], XmNlabelType, XmSTRING);  n++;
  377.     XtSetArg (args[n], XmNlabelString, xmsBlank);  n++;
  378.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  379.     XtSetArg (args[n], XmNleftWidget, COLORSET_LABEL); n++;
  380.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  381.     XtSetArg (args[n], XmNtopWidget, top); n++;
  382.     /*  
  383.      * create value
  384.      */
  385.     top = COLORSET_VALUE = XtCreateWidget ("label", xmLabelWidgetClass,
  386.       form, args, n);
  387.  
  388.     /*******************************************
  389.      * SEPARATOR
  390.      ******************************************/
  391.  
  392.     /*  
  393.      * set up arglist  
  394.      */
  395.     n = 0;
  396.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  397.     XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  398.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  399.     XtSetArg (args[n], XmNtopWidget, top); n++;
  400.     /*  
  401.      * create separator  
  402.      */
  403.     top = SEPARATOR2 = (Widget) 
  404.         XmCreateSeparatorGadget (form, "separator", args, n);
  405.  
  406.     /*  
  407.      * manage children
  408.      */
  409.     XtManageChildren (wChildren, NUM_CHILDREN);
  410.  
  411.     /* 
  412.      * Show info on current workspace
  413.      */
  414.     ShowCurrentWorkspaceInfo ();
  415.  
  416.     /*  
  417.      * realize widgets  
  418.      */
  419.     XtRealizeWidget (toplevel);
  420.  
  421.     /*
  422.      * Do these calls after the shell is realized.  
  423.      * They need a window created for the top level shell.
  424.      *
  425.      * HINT: See XtSetMappedWhenManaged(1) if you want to 
  426.      *       realize a widget to get a window, but need to
  427.      *       control when the map of the window occurs.
  428.      */
  429.     (void) DtWsmAddCurrentWorkspaceCallback (toplevel,
  430.         (DtWsmWsChangeProc) wschangecb, NULL);
  431.  
  432.     DtWsmOccupyAllWorkspaces (XtDisplay(toplevel), XtWindow(toplevel));
  433.  
  434.     /*  
  435.      * process events  
  436.      */
  437.     XtAppMainLoop (app_context);
  438. }
  439.  
  440.  
  441. /*-------------------------------------------------------------
  442.  *    Update the information for the current workspace
  443.  */
  444. static void ShowCurrentWorkspaceInfo ()
  445. {
  446.     Arg    args[10]; /*  arg list        */
  447.     register int n;    /*  arg count        */
  448.     Atom aWs;
  449.     int rval;
  450.     Display *dpy;
  451.     Window root;
  452.     DtWsmWorkspaceInfo *pWsInfo;
  453.     XmString xms;
  454.     char pch[512];
  455.     char *pchName;
  456.  
  457.     dpy = XtDisplay(toplevel);
  458.     root = XDefaultRootWindow(dpy);
  459.  
  460.     rval = DtWsmGetCurrentWorkspace(dpy, root, &aWs);
  461.  
  462.     if (rval == Success)
  463.     {
  464.     rval = DtWsmGetWorkspaceInfo (dpy, root, aWs, &pWsInfo);
  465.  
  466.     if (rval == Success)
  467.     {
  468.         /* workspace name */
  469.         pchName = XmGetAtomName (dpy, pWsInfo->workspace);
  470.         xms = XmStringCreateLocalized(pchName);
  471.  
  472.         n = 0;
  473.         XtSetArg (args[n], XmNlabelString, xms);  n++;
  474.         XtSetValues (WS_VALUE, args, n);
  475.  
  476.         XmStringFree (xms);
  477.         XtFree (pchName);
  478.  
  479.         /* workspace title */
  480.         xms = XmStringCreateLocalized(pWsInfo->pchTitle);
  481.  
  482.         n = 0;
  483.         XtSetArg (args[n], XmNlabelString, xms);  n++;
  484.         XtSetValues (TITLE_VALUE, args, n);
  485.  
  486.         XmStringFree (xms);
  487.  
  488.         /* workspace backdrop name */
  489.         if (pWsInfo->backdropName != None)
  490.         pchName = XmGetAtomName (dpy, pWsInfo->backdropName);
  491.         else
  492.         pchName = "<failed to load!>";
  493.         xms = XmStringCreateLocalized(pchName);
  494.  
  495.         n = 0;
  496.         XtSetArg (args[n], XmNlabelString, xms);  n++;
  497.         XtSetValues (BACKDROP_VALUE, args, n);
  498.  
  499.         XmStringFree (xms);
  500.         if (pWsInfo->backdropName != None)
  501.         XtFree (pchName);
  502.  
  503.         /* workspace colorset id */
  504.         sprintf (pch, "%d", pWsInfo->colorSetId);
  505.         xms = XmStringCreateLocalized(pch);
  506.  
  507.         n = 0;
  508.         XtSetArg (args[n], XmNlabelString, xms);  n++;
  509.         XtSetValues (COLORSET_VALUE, args, n);
  510.  
  511.         XmStringFree (xms);
  512.  
  513.         DtWsmFreeWorkspaceInfo (pWsInfo);
  514.     }
  515.     }
  516.  
  517.     if (rval != Success)
  518.     {
  519.     fprintf (stderr, "Failed to get workspace information.\n");
  520.     fprintf (stderr, "Is dtwm running?\n");
  521.     exit (1);
  522.     }
  523. }
  524.  
  525. /*-------------------------------------------------------------
  526.  *    quitCB - callback for button
  527.  */
  528. static void quitCB (w, client_data, call_data) 
  529. Widget    w;        /*  widget id        */
  530. XtPointer    client_data;    /*  data from application   */
  531. XtPointer    call_data;    /*  data from widget class  */
  532. {
  533.     exit (0);
  534. }
  535.  
  536.  
  537. /*-------------------------------------------------------------
  538.  *    updateCB - callback for show current workspace info
  539.  */
  540. static void updateCB (w, client_data, call_data) 
  541. Widget    w;        /*  widget id        */
  542. XtPointer    client_data;    /*  data from application   */
  543. XtPointer    call_data;    /*  data from widget class  */
  544. {
  545.  
  546.     ShowCurrentWorkspaceInfo ();
  547.  
  548. }
  549.  
  550. /*-------------------------------------------------------------
  551. **      wschangecb - callback for workspace switch
  552. */
  553. static DtWsmWsChangeProc
  554. wschangecb (w, atom, client_data)
  555. Widget  w;
  556. Atom    atom;
  557. XtPointer client_data;
  558. {
  559.     ShowCurrentWorkspaceInfo ();
  560. }
  561.  
  562.  
  563.  
  564. /*-------------------------------------------------------------
  565. **      data for X error handler
  566. */
  567. #define E_MAJOR_CODE            0
  568. #define E_MINOR_CODE            1
  569. #define E_RESOURCE_ID           2
  570. #define E_ERROR_SERIAL          3
  571. #define E_CURRENT_SERIAL        4
  572.  
  573. #define NUM_E_STRINGS           5
  574.  
  575. static char *pchErrorFormatNames [NUM_E_STRINGS] = {
  576.     "MajorCode",
  577.     "MinorCode",
  578.     "ResourceID",
  579.     "ErrorSerial",
  580.     "CurrentSerial"
  581. };
  582.  
  583. static char *pchErrorFormat [NUM_E_STRINGS];
  584.  
  585.  
  586. /*-------------------------------------------------------------
  587. **      HandleXErrors - catch X protocol errors
  588. */
  589. static int
  590. _HandleXErrors (display, errorEvent)
  591. Display  *display;
  592. XErrorEvent *errorEvent;
  593. {
  594.     char buffer[BUFSIZ];
  595.     char message[BUFSIZ];
  596.  
  597.     XGetErrorText (display, errorEvent->error_code, buffer, BUFSIZ);
  598.     fprintf (stderr, "\n*** X error occurred ***\n");
  599.     fprintf (stderr, "Description = '%s'\n  ", buffer);
  600.  
  601.     fprintf (stderr, pchErrorFormat[E_MAJOR_CODE], errorEvent->request_code);
  602.     sprintf(message, "%d", errorEvent->request_code);
  603.     XGetErrorDatabaseText (display, "XRequest", message, " ", buffer, BUFSIZ);
  604.     fprintf (stderr, " (%s)\n  ", buffer);
  605.     fprintf (stderr, pchErrorFormat[E_MINOR_CODE], errorEvent->minor_code);
  606.     fprintf (stderr, "\n  ");
  607.     fprintf (stderr, pchErrorFormat[E_RESOURCE_ID], errorEvent->resourceid);
  608.     fprintf (stderr, "\n  ");
  609.     fprintf (stderr, pchErrorFormat[E_ERROR_SERIAL], errorEvent->serial);
  610.     fprintf (stderr, "\n  ");
  611.     fprintf (stderr, pchErrorFormat[E_CURRENT_SERIAL],
  612.                         LastKnownRequestProcessed(display));
  613.     fprintf (stderr, "\n");
  614.  
  615.     return (0);
  616. }
  617.  
  618. /*-------------------------------------------------------------
  619. **    Setup the X error handler
  620. */
  621. static void
  622. InstallXErrorHandler ( display )
  623. Display *display;
  624. {
  625.     char buffer[BUFSIZ];
  626.     int i;
  627.  
  628.     /*
  629.      * Fetch the X error format strings from XErrorDB
  630.      */
  631.     for (i = 0; i< NUM_E_STRINGS; i++)
  632.     {
  633.         XGetErrorDatabaseText (display, "XlibMessage",
  634.                     pchErrorFormatNames[i], " %d ", buffer, BUFSIZ);
  635.  
  636.         pchErrorFormat[i] = (char *) XtMalloc (1+strlen(buffer));
  637.  
  638.         strcpy(pchErrorFormat[i], buffer);
  639.     }
  640.  
  641.     XSetErrorHandler (_HandleXErrors);
  642. }
  643.